<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>


    
</body>

 
<script>
    
     function a (obj){
        if ( obj == null) {
            return  null
        }else if (typeof obj === 'object') {
            if (Array.isArray(obj)) {
                return 'Array'
            }else{
                return typeof obj
            }
        }else if ( typeof obj =='number') {
            if (isNaN(obj)) {
                return 'NaN'
            }else{
                return typeof obj
            }
        } else{
            return typeof obj
        }

     }

     console.log(a());

   
     let b ={
         name:'小明',
         say:function(){
             console.log(this.name+'是我的朋友');
         },
         c:{
             name:'小红',
             say:function(){
                 return this.name
             }
         },
         d: [1,23,44,5]
     }

     function copy1 (obj){
         return JSON.parse(JSON.stringify(obj))
     }
     console.log(copy1(b)); //无法拷贝函数

     function copy2 (obj){
         return Object.assign(b)
     }
     console.log(copy2(b));
       b.c.name='小白'
     console.log(copy2(b));  //函数能拷贝，嵌套函数不能拷贝

     function copy3 (obj){
         let res = obj;
         if (typeof obj === 'object' && obj != 'null') {
             res = Object.prototype.toString.call(obj) == '[object Object]'?[]:{}
            
            for(let props in obj){
                res[props] = copy3(obj[props])
            }
         }
         return res

     }

     console.log(copy3(b));
     b.c.name='小白2'
     console.log(copy3(b));  //递归解决嵌套拷贝


     arr = [1,2,3,4,4,5,5,6,6,7];
      
      function newArr(arr){
        let newArr = [];
          for(let i in arr){
            if (newArr.indexOf(arr[i])=== -1) {
               newArr.push(arr[i])
            }
         
          }
          return newArr
      }

    console.log(newArr(arr));

    console.log( Array.from(new Set(arr)));
      
      
</script>

</html>